package com.xdog.web3.task;

import com.xdog.web3.service.impl.twitter.TwitterFollowDataServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Twitter关注用户定时任务
 */
@Slf4j
@Component
public class TwitterFollowUserTask {

    @Autowired
    private TwitterFollowDataServiceImpl twitterFollowDataService;

    /**
     * 定时加载Twitter关注用户数据
     * 每天凌晨2点执行
     */
    @Scheduled(cron = "0 0 0 5/5 * ?")
    public void loadTwitterFollowUsers() {
        log.info("开始执行Twitter关注用户数据加载任务");
        try {
            // 首先尝试从API获取数据
            twitterFollowDataService.fetchFollowUsersFromAPI("1554484759304503298", 20);

            log.info("Twitter关注用户数据加载任务执行完成");
        } catch (Exception e) {
            log.error("Twitter关注用户数据加载任务执行失败", e);
        }
    }
}
